package com.jpcc.vw.onlineRadio.adapter.item;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jpcc.vw.onlineRadio.R;
import com.jpcc.vw.onlineRadio.activity.AlbumDetailActivity;
import com.jpcc.vw.onlineRadio.model.bean.RecommendationEntity;
import com.jpcc.vw.onlineRadio.recycle.RecyclerView.BaseItem;

import java.text.SimpleDateFormat;
import java.util.Date;


public class DailyRecommendationItem extends BaseItem<RecommendationEntity> implements View.OnClickListener {

    private ImageView imv_album_cover;
    private TextView tv_album_title;
    private RecommendationEntity result;
    private TextView tv_item_count;
    private TextView tv_updateTime;

    public DailyRecommendationItem(ViewGroup parent) {
        super(parent);
    }

    @Override
    public int getRes() {
        return R.layout.adapter_recommendation;
    }

    @Override
    public void onCreateView(View rootView) {
        imv_album_cover = (ImageView) rootView.findViewById(R.id.imv_album_cover);
        tv_album_title = (TextView) rootView.findViewById(R.id.tv_album_title);
        tv_item_count = (TextView) rootView.findViewById(R.id.tv_item_count);
        imv_album_cover=(ImageView)rootView.findViewById(R.id.imv_cover);
        tv_updateTime=(TextView)rootView.findViewById(R.id.tv_updateTime);
    }

    @Override
    public void onBindView(RecommendationEntity recommendationEntity) {
        this.result = recommendationEntity;
//        tv_item_count.setVisibility(View.GONE);
        tv_item_count.setText(getPosition()+1 + "");
        tv_album_title.setText(result.getName());
        Glide.with(getContext()).load(result.getCover().getLarge().getUrl()).into(imv_album_cover);
        if(result.getUpdateTime()!=0){
            SimpleDateFormat format=new SimpleDateFormat("YYYY-MM-dd");
            tv_updateTime.setVisibility(View.VISIBLE);
            tv_updateTime.setText("Update:"+format.format(new Date(result.getUpdateTime())));
        }
        else{
            tv_updateTime.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getContext(), AlbumDetailActivity.class);
        intent.putExtra("key_album_id",this.result.getId());
        intent.putExtra("key_is_radio",false);
        intent.putExtra("key_from",4);
        getContext().startActivity(intent);
    }
}
